<template>
  <div class="achievement" v-cloak>
    <div class="bg_color"></div>
    <div style="height: 4px;position: absolute;z-index: 2222; width: 100%; top: 46px;background: #f0f0f0"></div>
    <div style="height: 50px;"></div>
    <div class="about-us" v-show="show">
      <div class="content-box menu-box service-box">
        <ul class="menu">
          <li :class="{active : currentIndex == index}"  v-for="(item,index) in date_option" @click="tabDay(index,item)"><span >{{item.title}}</span><span>{{item.date_msg}}</span></li>
          <div class="clearfix"></div>
        </ul>
      </div>
      <div class="content-box">
        <ul class="time">
          <li v-for="(item,index) in time_right" >
            <button v-if="item.status == ''" :class="{ active : serviceIndex == index }"  @click="tabTime(index)"><span>{{item.time_msg}}</span><span>{{item.status}}</span></button>
            <button class="busy" v-if="item.status == '忙'"><span>{{item.time_msg}}</span><span>{{item.status}}</span></button>
            <button class="busy"  v-if="item.status == '过'"><span>{{item.time_msg}}</span></button>
            <button class="recommend" v-if="item.status == '荐'" :class="{ active : serviceIndex == index }" @click="tabTime(index)"><span>{{item.time_msg}}</span><span>{{item.status}}</span></button>
          </li>
        </ul>
      </div>
      <div class="content-box">
        <div class="confirm-box" @click="determine">
          <button>确定选择</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import { TransferDom } from 'vux'
  export default {
    name: 'ServiceTime',
    data () {
      return {
        show: false,
        date_option: [],
        time_option: [],
        currentIndex: 0,
        date_code: '',
        time_right: {},
        serviceIndex: 0,
        date_msg: '',
        time_msg: ''
      }
    },
    directives: {
      TransferDom
    },
    methods: {
      setmode: function (name, content) {
        let mode = this.$chaos.config('mode')
        if (mode === 'website') {
          sessionStorage[name] = JSON.stringify(content)
        } else {
          localStorage[name] = JSON.stringify(content)
        }
      },
      determine: function () {
        if (this.time_msg === '') {
          this.$vux.toast.show({
            text: '请选择服务时间',
            type: 'text',
            width: '180px',
            position: 'bottom'
          })
          return false
        }
        this.setmode('service', 'two')
        this.setmode('datemsg', this.date_msg)
        this.setmode('timemsg', this.time_msg)
        setTimeout(function () {
          window.history.back(-1)
        }, 300)
      },
      tabTime: function (index) {
        var thisObj = this
        thisObj.serviceIndex = index
        thisObj.time_msg = thisObj.time_right[index].time_msg
      },
      tabDay: function (index, dateoption) {
        var thisObj = this
        thisObj.currentIndex = index
        thisObj.date_msg = dateoption.date_msg
        thisObj.date_code = dateoption.date_code
        thisObj.$chaos.ajax({
          data: {
            choose_date: thisObj.date_code
          },
          slient: true,
          userinfo: false,
          url: 'Service/getServiceTime',
          callback: function (type, res) {
            if (res.status === 'SUCCESS') {
              thisObj.time_right = res.result.time_option
            } else {
              thisObj.$vux.toast.show({
                text: res.result.msg,
                type: 'text',
                width: '180px',
                position: 'bottom'
              })
            }
          }
        })
      },
      verify: function () {
        var thisObj = this
        this.$chaos.setTitle('服务时间')
        this.$store.commit('headerShow', true)
        this.$store.commit('title', '服务时间')
        this.$store.commit('footerShow', false)
        this.setmode('need-refresh', true)
        thisObj.$chaos.ajax({
          data: {
            choose_date: ''
          },
          slient: true,
          userinfo: true,
          url: 'Service/getServiceTime',
          callback: function (type, res) {
            if (res.status === 'SUCCESS') {
              thisObj.date_msg = res.result.date_option[0].date_msg
              thisObj.time_msg = res.result.time_option[0].time_msg
              thisObj.date_option = res.result.date_option
              thisObj.time_option = res.result.time_option
              thisObj.time_right = thisObj.time_option
              console.log(thisObj.time_right)
              thisObj.show = true
            } else {
              thisObj.$vux.toast.show({
                text: res.result.msg,
                type: 'text',
                width: '180px',
                position: 'bottom'
              })
            }
          }
        })
      },
      demand: function () {
        var thisObj = this
        if (thisObj.content === '') {
          thisObj.$vux.toast.show({
            text: '请输入您的备注需求',
            type: 'text',
            width: '180px',
            position: 'bottom'
          })
          return false
        }
      }
    },
    created: function () {
      this.verify()
    },
    mounted: function () {
      window.scrollTo(0, 2000)
    },
    watch: {
      '$route': 'verify'
    }
  }
</script>
<style scoped>
  [v-cloak] {
    display: block;
  }
  .service-box {
    top: 0px;
    background-color: white;
  }
  input, button, textarea {
    border: 0;
    margin: 0;
    padding: 0;
    outline: none;
    resize: none;
  }
  .menu-box {
    top: 50px;
    background-color: #f9f9f9;
    z-index: 100;
  }
  .weather-box, .menu-box {
    overflow: auto;
    position: fixed;
    width: 100%;
  }
  .content-box {
    padding: 0px 12px;
  }
  .service-box .menu {
    width: calc(100% - 30px);
  }
  .service-box .menu {
    padding-top: 10px;
  }
  .menu {
    line-height: 45px;
    width: 120%;
    overflow: hidden;
    height: 45px;
    position: relative;
  }
  .service-box .menu li {
    line-height: 18px;
    text-align: center;
  }
  .menu li {
    float: left;
    width: 14%;
    line-height: 45px;
    text-align: center;
  }
  .service-box ul li span {
    display: block;
  }
  .service-box .menu li span:nth-child(2) {
    font-size: 12px;
  }
  .service-box ul li span {
    display: block;
  }
  .clearfix {
    clear: both;
  }
  .time {
    padding-top: 15px;
    padding-bottom: 2px;
    margin-top: 55px;
  }
  .time li {
    float: left;
    width: 25%;
    height: 35px;
    margin: 0 auto 10px;
    text-align: center;
  }
  .time .active {
    width: 90%;
    background-color: #ffa128;
    border: 1px solid #ffa128;
    text-align: center;
    padding: 3px 0px;
    border-radius: 8px;
    height: 100%;
  }
  .time .active  span{
    color: #fff;
  }
  .time button {
    width: 90%;
    background-color: #fff;
    border: 1px solid #dadada;
    text-align: center;
    padding: 3px 0px;
    border-radius: 8px;
    height: 100%;
  }
  .time button span {
    color: #333;
    line-height: 15px;
  }
  .time li span {
    display: block;
  }
  .time button span {
    color: #333;
    line-height: 15px;
  }
  .time li span {
    display: block;
  }
  .time .busy {
    width: 90%;
    background-color: #dfdfdf;
    border: 1px solid #dfdfdf;
    text-align: center;
    padding: 3px 0px;
    border-radius: 8px;
    height: 100%;
  }
  .time .busy span {
    color: #fff;
  }
  .time button span {
    color: #333;
    line-height: 15px;
  }
  .time li span {
    display: block;
  }
  .time .recommend {
    width: 90%;
    background-color: #fff;
    border: 1px solid #dadada;
    text-align: center;
    padding: 3px 0px;
    border-radius: 8px;
    height: 100%;
  }
  .time .recommend span {
    color: #ff2323;
  }
  .service-box .menu .active span{
    color: #ffa128;
  }
  .time button span {
    color: #333;
    line-height: 15px;
  }
  .time li span {
    display: block;
  }
  .confirm-box {
    position: fixed;
    bottom: 0px;
    width: calc(100% - 30px);
    padding: 5px 15px;
    background-color: white;
    left: 0px;
  }
  .content-box .confirm-box button {
    width: 100%;
    background-color: #ffa128;
    height: 38px;
    line-height: 38px;
    color: white;
    text-align: center;
    border-radius: 4px;
  }
</style>
